<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/md5.asp"-->
<!--#include file="../common/admin.asp"-->
<%
id=request.QueryString("edit")
if id<>"" then
	  set rsm=server.CreateObject("adodb.recordset")
	  sql="select * from API where id="&id&""
	  rsm.open sql,conn,1,3
	  if not rsm.eof then
          nick=rsm("nick")
		  title=rsm("title")
		  key=rsm("key")
		  secret=rsm("secret")
		  typevalue=rsm("type")
		  webtype=rsm("webtype")
		  start=rsm("start")
		  max=rsm("max")
	  rsm.close
	  set rsm=nothing
	  end if
end if
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>main</title>
<link href="../css/style.css" rel="stylesheet" type="text/css"/>
</head>

<body>
<div class="main">
  <div class="main-title">api <a href="?add=ok">添加</a></div>
  <div class="main-content">
<%if request.QueryString("add")="ok" then%>
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <form action="" method="post">
  <tr>
    <td width="29%" bgcolor="#FFFFFF">用户名id</td>
    <td width="71%" bgcolor="#FFFFFF"><input name="nick" type="text" class="input" id="nick" /></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF"> api名称</td>
    <td bgcolor="#FFFFFF"><input name="title" type="text" class="input" id="title" /></td>
    </tr>
  <tr>
    <td bgcolor="#FFFFFF">apiID</td>
    <td bgcolor="#FFFFFF"><input name="key" type="text" class="input" id="key" /></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF">apiSecret</td>
    <td bgcolor="#FFFFFF"><input name="secret" type="text" class="input" id="secret" /></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF">类型</td>
    <td bgcolor="#FFFFFF"><select name="type" id="type">
      <option value="0">前台</option>
      <option value="1">后台</option>
    </select></td>
    </tr>
  <tr>
    <td bgcolor="#FFFFFF">网站类型</td>
    <td bgcolor="#FFFFFF"><select name="webtype" id="webtype">
       <%
					  set rsm=server.CreateObject("adodb.recordset")
					  sql="select * from web"
					  rsm.open sql,conn,1,3
					  if not rsm.eof then
					  do while not rsm.eof
					  %>
      <option value="<%=rsm("id")%>"<%if webtype=rsm("id") then response.Write " selected"%>><%=rsm("title")%></option>
       <%
					  rsm.movenext
					  loop
					  rsm.close
					  set rsm=nothing
					  end if		 
					  %>
    </select></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF">起始调用api次数</td>
    <td bgcolor="#FFFFFF"><input name="start" type="text" class="input" id="start" /></td>
    </tr>
  <tr>
    <td bgcolor="#FFFFFF">最大调用api次数</td>
    <td bgcolor="#FFFFFF"><input name="max" type="text" class="input" id="max" /></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF">&nbsp;</td>
    <td bgcolor="#FFFFFF"><input type="submit" name="button" id="button" value="添加" /> <a href="javascript:;" onClick="javascript:history.back(-1);">返回</a></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF">&nbsp;</td>
    <td bgcolor="#FFFFFF">&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF">&nbsp;</td>
    <td bgcolor="#FFFFFF">&nbsp;</td>
    </tr>
    </form>
  </table>
<%elseif request.QueryString("edit")<>"" then%>
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <form action="" method="post">
  <tr>
    <td width="29%" bgcolor="#FFFFFF">用户名id</td>
    <td width="71%" bgcolor="#FFFFFF"><input name="nick" type="text" class="input" id="nick" value="<%=nick%>" /></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF"> api名称</td>
    <td bgcolor="#FFFFFF"><input name="title" type="text" class="input" id="title" value="<%=title%>" /></td>
    </tr>
  <tr>
    <td bgcolor="#FFFFFF">apiID</td>
    <td bgcolor="#FFFFFF"><input name="key" type="text" class="input" id="key" value="<%=key%>" /></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF">apiSecret</td>
    <td bgcolor="#FFFFFF"><input name="secret" type="text" class="input" id="secret" value="<%=secret%>" /></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF">类型</td>
    <td bgcolor="#FFFFFF"><select name="type" id="type">
      <option value="0"<%if typevalue="0" then response.Write " selected"%>>前台</option>
      <option value="1"<%if typevalue="1" then response.Write " selected"%>>后台</option>
    </select></td>
    </tr>
  <tr>
    <td bgcolor="#FFFFFF">网站类型</td>
    <td bgcolor="#FFFFFF"><select name="webtype" id="webtype">
      <%
					  set rsm=server.CreateObject("adodb.recordset")
					  sql="select * from web"
					  rsm.open sql,conn,1,3
					  if not rsm.eof then
					  do while not rsm.eof
					  %>
      <option value="<%=rsm("id")%>"<%if webtype=rsm("id") then response.Write " selected"%>><%=rsm("title")%></option>
      <%
					  rsm.movenext
					  loop
					  rsm.close
					  set rsm=nothing
					  end if		 
					  %>
    </select></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF">起始调用api次数</td>
    <td bgcolor="#FFFFFF"><input name="start" type="text" class="input" id="start" value="<%=start%>" /></td>
    </tr>
  <tr>
    <td bgcolor="#FFFFFF">最大调用api次数</td>
    <td bgcolor="#FFFFFF"><input name="max" type="text" class="input" id="max" value="<%=max%>" /></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF">&nbsp;</td>
    <td bgcolor="#FFFFFF"><input type="submit" name="button" id="button" value="保存" /> <a href="javascript:;" onClick="javascript:history.back(-1);">取消</a></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF">&nbsp;</td>
    <td bgcolor="#FFFFFF">&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF">&nbsp;</td>
    <td bgcolor="#FFFFFF">&nbsp;</td>
    </tr>
    </form>
  </table>
<%else%>
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <tr>
    <td bgcolor="#FFFFFF">用户名id</td>
    <td bgcolor="#FFFFFF"><strong> api名称</strong></td>
    <td bgcolor="#FFFFFF"><strong>apiKey</strong></td>
    <td bgcolor="#FFFFFF"><strong>apiSecret</strong></td>
    <td bgcolor="#FFFFFF"><strong>类型</strong></td>
    <td bgcolor="#FFFFFF"><strong>网站类型</strong></td>
    <td bgcolor="#FFFFFF"><strong>起始调用api次数</strong></td>
    <td bgcolor="#FFFFFF"><strong>最大调用api次数</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>操作</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>删除</strong></td>
    </tr>
     <%
					  set rsu=server.CreateObject("adodb.recordset")
					  sql="select * from API order by type"
					  rsu.open sql,conn,1,3
					  if not rsu.eof then
					  do while not rsu.eof
					  %>
  <tr>
    <td bgcolor="#FFFFFF"><%=rsu("nick")%></td>
    <td bgcolor="#FFFFFF"><%=rsu("title")%></td>
    <td bgcolor="#FFFFFF" title="<%=rsu("key")%>"><%=left(rsu("key"),20)%></td>
    <td bgcolor="#FFFFFF"><%=rsu("secret")%></td>
    <td bgcolor="#FFFFFF"><%if rsu("type")="0" then response.Write "前台" else response.Write "后台"%></td>
    <td bgcolor="#FFFFFF"><%set rss=conn.execute("select title from web where id="&rsu("webtype"))
		                               if not rss.eof then
									   response.write rss("title")
									   end if
									   set rss=nothing%></td>
    <td bgcolor="#FFFFFF"><%=rsu("start")%></td>
    <td bgcolor="#FFFFFF"><%=rsu("max")%></td>
    <td align="center" bgcolor="#FFFFFF"><a href="?edit=<%=rsu("id")%>">修改</a></td>
    <td align="center" bgcolor="#FFFFFF"><a href="?del=<%=rsu("id")%>">删除</a></td>
    </tr>
    <%
					  rsu.movenext
					  loop
					  rsu.close
					  set rsu=nothing
					  end if		 
					  %>
  
  </table>
<%end if%>
</div>
</div>
</body>
</html>
<%
if request.Form("button")="添加" then

	nick=request.Form("nick")
	title=request.Form("title")
	key=request.Form("key")
	secret=request.Form("secret")
	typevalue=request.Form("type")
	webtype=request.Form("webtype")
	start=request.Form("start")
	max=request.Form("max")

	set rsu=server.createobject("adodb.recordset")
	sql="select * from API"
	rsu.open sql,conn,1,3
	rsu.addnew
	rsu("nick")=nick
	rsu("title")=title
	rsu("key")=key
	rsu("secret")=secret
	rsu("type")=typevalue
	rsu("webtype")=webtype
	rsu("start")=start
	rsu("max")=max
	rsu.update
	response.write"<script language=JavaScript>{window.alert('添加成功！');window.location.href='view.asp';}</script>"
	rsu.close
	set rsu=nothing
	
elseif request.Form("button")="保存" then

	nick=request.Form("nick")
	title=request.Form("title")
	key=request.Form("key")
	secret=request.Form("secret")
	typevalue=request.Form("type")
	webtype=request.Form("webtype")
	start=request.Form("start")
	max=request.Form("max")

	set rsu=server.createobject("adodb.recordset")
	sql="select * from API where id="&id&""
	rsu.open sql,conn,1,3
	rsu("nick")=nick
	rsu("title")=title
	rsu("key")=key
	rsu("secret")=secret
	rsu("type")=typevalue
	rsu("webtype")=webtype
	rsu("start")=start
	rsu("max")=max
	rsu.update
	response.write"<script language=JavaScript>{window.alert('保存成功！');window.location.href='view.asp';}</script>"
	rsu.close
	set rsu=nothing

elseif request.QueryString("del")<>"" then
    conn.execute("delete from API where id="&request.QueryString("del")&"")
	response.Redirect "view.asp"
end if
%>